home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ULARN.ARJ / ULARN.TAR / ularn / scores.c < prev    next >
C/C++ Source or Header  |  1989-10-25  |  19KB  |  834 lines

  1. /* scores.c
  2.  *
  3.  *    Functions in this file are:
  4.  *
  5.  *    readboard()     
  6.  *        Function to read in the scoreboard into a static buffer
  7.  *    writeboard()    
  8.  *        Function to write the scoreboard from readboard()'s buffer
  9.  *    makeboard()     
  10.  *        Function to create a new scoreboard (wipe out old one)
  11.  *    hashewon()     
  12.  *        Function to return 1 if player has won a game before, else 0
  13.  *    long paytaxes(x)     
  14.  *        Function to pay taxes if any are due
  15.  *    winshou()        
  16.  *        Subroutine to print out the winning scoreboard
  17.  *    shou(x)            
  18.  *        Subroutine to print out the non-winners scoreboard
  19.  *    showscores()        
  20.  *        Function to show the scoreboard on the terminal
  21.  *    showallscores()    
  22.  *        Function to show scores and the iven lists that go with them
  23.  *    sortboard()        
  24.  *        Function to sort the scoreboard
  25.  *    newscore(score, whoo, whyded, winner)     
  26.  *        Function to add entry to scoreboard
  27.  *    new1sub(score,i,whoo,taxes)           
  28.  *        Subroutine to put player into a 
  29.  *    new2sub(score,i,whoo,whyded)           
  30.  *        Subroutine to put player into a 
  31.  *    died(x)     
  32.  *        Subroutine to record who played larn, and what the score was
  33.  *    diedsub(x) 
  34.  *        Subroutine to print out a line showing player when he is killed
  35.  */
  36. #include "header.h"
  37.  
  38. struct scofmt /*This is the structure for the scoreboard     */
  39. {
  40.     long    score;        /* the score of the player     */
  41.     long    suid;        /* the user id number of the player*/
  42.     short    what;        /* the number of the monster that killedplayer*/
  43.     short    level;        /* the level player was on when he died */
  44.     short    hardlev;    /* the level of difficulty player played at*/
  45.     short    order;        /* the relative ordering place of this entry*/
  46.     char    who[40];    /* the name of the character         */
  47.     char    char_class[20]; /* the character class */
  48.     char    sciv[26][2];    /* this is the inventory list of the character*/
  49. };
  50.  
  51. /* This is the structure for the winning scoreboard */
  52. struct wscofmt {
  53.     long    score;        /* the score of the player    */
  54.     long    timeused;    /* the time used in mobuls to win the game*/
  55.     long    taxes;        /* taxes he owes to LRS     */
  56.     long    suid;        /* the user id number of the player*/
  57.     short    hardlev;    /* the level of difficulty player played at*/
  58.     short    order;        /* the relative ordering place of this entry*/
  59.     char    who[40];    /* the name of the character         */
  60.     char    char_class[20]; /* the character class */
  61. };
  62.  
  63. static struct scofmt sco[SCORESIZE];    /* the structure for the scoreboard  */
  64. static struct wscofmt winr[SCORESIZE];    /* struct for the winning scoreboard */
  65.  
  66. static char    *whydead[] = {
  67. "quit",                     /* 0 */
  68. "suspended", 
  69. "self - annihilated", 
  70. "shot by an arrow",
  71. "hit by a dart",
  72. "fell into a pit",                 /* 5 */
  73. "fell into a pit to HELL",
  74. "a winner", 
  75. "trapped in solid rock", 
  76. "killed by a missing save file",
  77. "killed by an old save file",             /* 10 */
  78. "caught by the greedy cheater checker trap",
  79. "killed by a protected save file", 
  80. "killed his family and committed suicide", /* 13 */
  81. "erased by a wayward finger",
  82. "fell through a trap door to HELL",        /* 15 */
  83. "fell through a trap door",
  84. "drank some poisonous water",
  85. "fried by an electric shock", 
  86. "slipped on a volcano shaft",
  87. "killed by a stupid act of frustration",     /* 20 */
  88. "attacked by a revolting demon",
  89. "hit by his own magic",            /* 22 */
  90. "demolished by an unseen attacker",
  91. "fell into the dreadful sleep",
  92. "killed by an exploding chest",            /* 25 */
  93. "killed by a missing maze data file",
  94. "annihilated in a sphere",
  95. "died a post mortem death",
  96. "wasted by a malloc() failure"            /* 29 */
  97. };
  98.  
  99.  
  100. /*
  101.  *    readboard()     Function to read in the scoreboard into a static buffer
  102.  *
  103.  *    returns -1 if unable to read in the scoreboard, returns 0 if all is OK
  104.  */
  105. readboard()
  106. {
  107.     FILE *fp;
  108.  
  109.     if ((fp = fopen(scorefile, "r")) == (FILE *)NULL) {
  110.         fprintf(stderr, "Can't open scorefile for reading\n"); 
  111.         fflush(stderr);
  112.         return(-1); 
  113.     }
  114.     if (fread((char *)sco, sizeof(sco), 1, fp) != 1) {
  115.         fprintf(stderr, "Can't read scoreboard\n");
  116.         fflush(stderr);
  117.         fclose(fp);
  118.         return(-1);
  119.     }
  120.     if (fread((char *)winr, sizeof(winr), 1, fp) != 1) {
  121.         fprintf(stderr, "Can't read scoreboard\n");
  122.         fflush(stderr);
  123.         fclose(fp);
  124.         return(-1);
  125.     }
  126.     fflush(fp);
  127.     fclose(fp);  
  128.     return(0);
  129. }
  130.  
  131.  
  132. /*
  133.  *    writeboard()    
  134.  *        Function to write the scoreboard from readboard()'s buffer
  135.  *
  136.  *    returns -1 if unable to write the scoreboard, returns 0 if all is OK
  137.  */
  138. writeboard()
  139. {
  140.     FILE *fp;
  141.  
  142.     if ((fp = fopen(scorefile, "w")) == (FILE *)NULL) {
  143.         lprcat("Can't open scorefile for writing\n"); 
  144.         lflush();
  145.         return(-1); 
  146.     }
  147.     if (fwrite((char * )sco, sizeof(sco), 1, fp) != 1) {
  148.         lprcat("Can't write scorefile\n"); 
  149.         lflush();
  150.         fclose(fp);
  151.         return(-1); 
  152.     }
  153.     if (fwrite((char * )winr, sizeof(winr), 1, fp) != 1) {
  154.         lprcat("Can't write scorefile\n"); 
  155.         lflush();
  156.         fclose(fp);
  157.         return(-1); 
  158.     }
  159.     fflush(fp);
  160.     fclose(fp);  
  161.     return(0);
  162. }
  163.  
  164.  
  165. /*
  166.  *        Function to create a new scoreboard (wipe out old one)
  167.  *    makeboard()         
  168.  *
  169.  *    returns -1 if unable to write the scoreboard, returns 0 if all is OK
  170.  */
  171. makeboard()
  172. {
  173.     int    i;
  174.  
  175.     for (i = 0; i < SCORESIZE; i++) {
  176.         winr[i].taxes = winr[i].score = sco[i].score = 0;
  177.         winr[i].order = sco[i].order = i;
  178.     }
  179.     if (writeboard()) 
  180.         return(-1);
  181.     chmod(scorefile, 0666);
  182.     return(0);
  183. }
  184.  
  185.  
  186. /*
  187.  *    Function to return 1 if player has won a game before, else 0
  188.  *
  189.  *    hashewon()     
  190.  *
  191.  *    This function also sets c[HARDGAME] to appropriate value -- 0 if not a
  192.  *    winner, otherwise the next level of difficulty listed in the winners
  193.  *    scoreboard.  This function also sets outstanding_taxes to the value in
  194.  *    the winners scoreboard.
  195.  */
  196. hashewon()
  197. {
  198.     register int    i;
  199.  
  200.     c[HARDGAME] = 0;
  201.  
  202.     if (readboard() < 0) 
  203.         return(0);    /* can't find scoreboard */
  204.  
  205.     for (i = 0; i < SCORESIZE; i++)    /* search through winners scoreboard */
  206.         if (winr[i].suid == userid)
  207.             if (winr[i].score > 0) {
  208.                 c[HARDGAME] = winr[i].hardlev + 1;
  209.                 outstanding_taxes = winr[i].taxes;
  210.                 return(1);
  211.             }
  212.     return(0);
  213. }
  214.  
  215.  
  216. /*
  217.  *    long paytaxes(x)         Function to pay taxes if any are due
  218.  *
  219.  *    Enter with the amount (in gp) to pay on the taxes.
  220.  *    Returns amount actually paid.
  221.  */
  222. long    paytaxes(x)
  223. long    x;
  224. {
  225.     int    i;
  226.     long    amt;
  227.  
  228.     if (x <= 0) 
  229.         return(0L);
  230.  
  231.     if (readboard() < 0) 
  232.         return(0L);
  233.  
  234.     for (i = 0; i < SCORESIZE; i++)
  235.  
  236.         /* look for players winning entry */
  237.         if (winr[i].suid == userid)
  238.  
  239.             /* search for a winning entry for the player */ {
  240.             if (winr[i].score > 0) 
  241.                 amt = winr[i].taxes;
  242.                 if (x < amt) 
  243.                     amt = x;
  244.                 winr[i].taxes -= amt;
  245.                 outstanding_taxes -= amt;
  246.                 if (writeboard() < 0) 
  247.                     return(0);
  248.                 return(amt);
  249.             }
  250.     return(0L);    /* couldn't find user on winning scoreboard */
  251. }
  252.  
  253.  
  254. /*
  255.  *    winshou()        Subroutine to print out the winning scoreboard
  256.  *
  257.  *    Returns the number of players on scoreboard that were shown 
  258.  */
  259. winshou()
  260. {
  261.     struct wscofmt *p;
  262.     register int    i, j, count;
  263.  
  264.     /* is there anyone on the scoreboard? */
  265.     for (count = j = i = 0; i < SCORESIZE; i++)
  266.         if (winr[i].score != 0) { 
  267.             j++; 
  268.             break; 
  269.         }
  270.  
  271.     if (j) {
  272.  
  273.           /*12345678901234567890123456789012345678901234567890123*/
  274.     puts("\n   Score       Diff   Time Needed  Ularn Winners List");
  275.  
  276.         /* needed to print out the */
  277.         /* winners in order */
  278.         for (i = 0; i < SCORESIZE; i++)
  279.           for (j = 0; j < SCORESIZE; j++) {
  280.             p = &winr[j];/*pointer to the scoreboard entry*/
  281.             if (p->order == i) {
  282.                 if (p->score) {
  283.                   count++;
  284.                   printf("%-10ld%8d%8d Mobuls  (%s) %s\n",
  285.                     (long)p->score,
  286.                     p->hardlev, 
  287.                     p->timeused, 
  288.                     p->char_class,
  289.                     p->who);
  290.                   fflush(stdout);
  291.                 }
  292.                 break;
  293.              }
  294.           }
  295.     }
  296.     return(count);    /* return number of people on scoreboard */
  297. }
  298.  
  299.  
  300. /*
  301.  *    shou(x)            
  302.  *    int x;
  303.  *        Subroutine to print out the non-winners scoreboard
  304.  *
  305.  *    Enter with 0 to list the scores, enter with 1 to list inventories too
  306.  *    Returns the number of players on scoreboard that were shown 
  307.  */
  308. shou(x)
  309. int    x;
  310. {
  311.     int    i, j, n;
  312.     int    count;
  313.  
  314.     /* is the scoreboard empty? */
  315.     for (count = j = i = 0; i < SCORESIZE; i++)    
  316.         if (sco[i].score != 0) { 
  317.             j++; 
  318.             break; 
  319.         }
  320.  
  321.     if (j) {
  322.         puts("\n  Score Diff  Ularn Visitor Log");
  323.         for (i = 0; i < SCORESIZE; i++)
  324.             for (j = 0; j < SCORESIZE; j++)
  325.                 if (sco[j].order == i) {
  326.                 if (sco[j].score) {
  327.                    count++;
  328.                    printf("%7ld %3ld   (%s) %s ",
  329.                         (long)sco[j].score, 
  330.                     (long)sco[j].hardlev, 
  331.                     sco[j].char_class,
  332.                     sco[j].who);
  333.                    if (sco[j].what < 256)
  334.                        printf("killed by a %s", 
  335.                     monster[sco[j].what].name);
  336.                    else {
  337.                     int foo = sco[j].what - 256;
  338.                            if (!sex && (foo == 13 || foo == 22))
  339.                         switch(foo) {
  340.                         case 13 : 
  341.             printf("killed her family and committed suicide");
  342.                             break;
  343.                         case 22 :
  344.             printf("hit by her own magic");
  345.                             break;
  346.                         }
  347.                     else
  348.                         printf("%s", whydead[foo]);
  349.                    }
  350.                    if (x != 263)
  351.                      printf(" on %s", 
  352.                         levelname[sco[j].level]);
  353.                    if (x) {
  354.                     for (n = 0; n < 26; n++) { 
  355.                        iven[n] = sco[j].sciv[n][0]; 
  356.                        ivenarg[n] = sco[j].sciv[n][1]; 
  357.                     }
  358.                       for (n = 0; n < 26; n++)
  359.                         if (iven[n])  {
  360.                             srcount = 0; 
  361.                             showscore3(n); 
  362.                         }
  363.                     }
  364.                     putchar('\n');
  365.                     fflush(stdout);
  366.                 }
  367.                 j = SCORESIZE;
  368.             }
  369.     }
  370.     return(count);    /* return the number of players just shown */
  371. }
  372.  
  373.  
  374. /*
  375.  *    showscores()        Function to show the scoreboard on the terminal
  376.  *
  377.  *    Returns nothing of value
  378.  */
  379. static char    esb[] = "The scoreboard is empty.\n";
  380.  
  381. showscores()
  382. {
  383.     int    i, j;
  384.  
  385.     if (readboard() < 0)
  386.         return;
  387.     i = winshou();
  388.     j = shou(0);
  389.  
  390.     if (i + j == 0) 
  391.         puts(esb); 
  392.     else 
  393.         putchar('\n');
  394.     lflush();
  395. }
  396.  
  397.  
  398. /*
  399.  *    showallscores()    
  400.  *        Function to show scores and the iven lists that go with them
  401.  *
  402.  *    Returns nothing of value
  403.  */
  404. showallscores()
  405. {
  406.     int    i, j;
  407.  
  408.  
  409.     if (readboard() < 0) 
  410.         return;
  411.  
  412.     c[WEAR] = c[WIELD] = c[SHIELD] = -1;
  413.  
  414.     for (i = 0; i < MAXPOTION; i++) 
  415.         potionname[i][0] = ' ';
  416.     for (i = 0; i < MAXSCROLL; i++) 
  417.         scrollname[i][0] = ' ';
  418.  
  419.     i = winshou();  
  420.     j = shou(1);
  421.  
  422.     if (i + j == 0)
  423.         puts(esb); 
  424.     else
  425.         putchar('\n');
  426.  
  427. }
  428.  
  429.  
  430. /*
  431.  *    sortboard()        Function to sort the scoreboard
  432.  *
  433.  *    Returns 0 if no sorting done, else returns 1
  434.  */
  435. sortboard()
  436. {
  437.     int    i, j, pos;
  438.     long    jdat;
  439.  
  440.     for (i = 0; i < SCORESIZE; i++) 
  441.         sco[i].order = winr[i].order = -1;
  442.     pos = 0;
  443.     while (pos < SCORESIZE) {
  444.         jdat = 0;
  445.         for (i = 0; i < SCORESIZE; i++)
  446.             if ((sco[i].order < 0) && (sco[i].score >= jdat)) { 
  447.                 j = i;  
  448.                 jdat = sco[i].score; 
  449.             }
  450.         sco[j].order = pos++;
  451.     }
  452.     pos = 0;
  453.     while (pos < SCORESIZE) {
  454.         jdat = 0;
  455.         for (i = 0; i < SCORESIZE; i++)
  456.             if ((winr[i].order < 0) && (winr[i].score >= jdat)) { 
  457.                 j = i;  
  458.                 jdat = winr[i].score; 
  459.             }
  460.         winr[j].order = pos++;
  461.     }
  462.     return(1);
  463. }
  464.  
  465.  
  466. /*
  467.  *        Function to add entry to scoreboard
  468.  *    newscore(score, whoo, whyded, winner)     
  469.  *    int score, winner, whyded;
  470.  *    char *whoo;
  471.  *
  472.  *    Enter with the total score in gp in score,  players name in whoo,
  473.  *        died() reason # in whyded, and TRUE/FALSE in winner if a winner
  474.  *    ex.        newscore(1000, "player 1", 32, 0);
  475.  */
  476. newscore(score, whoo, whyded, winner)
  477. long    score;
  478. int    winner, whyded;
  479. char    *whoo;
  480. {
  481.     int    i;
  482.     long    taxes;
  483.  
  484.     if (readboard() < 0) 
  485.         return;     /*    do the scoreboard    */
  486.  
  487.     /* if a winner then delete all non-winning scores */
  488.     if (cheat) 
  489.         winner = 0;    /* if he cheated, don't let him win */
  490.  
  491.     if (winner) {
  492.         for (i = 0; i < SCORESIZE; i++)
  493.             if (sco[i].suid == userid)
  494.                 sco[i].score = 0;
  495.         taxes = score * TAXRATE;
  496.         score += 100000 * c[HARDGAME];    /* bonus for winning */
  497.  
  498. /* if he has a slot on the winning scoreboard update it if greater score*/
  499.         for (i = 0; i < SCORESIZE; i++) 
  500.             if (winr[i].suid == userid) { 
  501.                 new1sub(score, i, whoo, taxes); 
  502.                 return; 
  503.             }
  504.  
  505. /* he had no entry. look for last entry and see if he has a greater score */
  506.         for (i = 0; i < SCORESIZE; i++) 
  507.             if (winr[i].order == SCORESIZE - 1) { 
  508.                 new1sub(score, i, whoo, taxes); 
  509.                 return; 
  510.             }
  511.     } else if (!cheat) /* for not winning scoreboard */ {
  512.     /* if he has a slot on the scoreboard update it if greater score */
  513.         for (i = 0; i < SCORESIZE; i++) 
  514.             if (sco[i].suid == userid) { 
  515.                 new2sub(score, i, whoo, whyded); 
  516.                 return; 
  517.             }
  518.  
  519. /* he had no entry. look for last entry and see if he has a greater score */
  520.         for (i = 0; i < SCORESIZE; i++)
  521.             if (sco[i].order == SCORESIZE - 1) { 
  522.                 new2sub(score, i, whoo, whyded); 
  523.                 return; 
  524.             }
  525.     }
  526. }
  527.  
  528.  
  529. /*
  530.  *    new1sub(score,i,whoo,taxes)       Subroutine to put player into a 
  531.  *    int score,i,whyded,taxes;      winning scoreboard entry if his score
  532.  *    char *whoo;                 is high enough
  533.  *
  534.  *    Enter with the total score in gp in score,  players name in whoo,
  535.  *        died() reason # in whyded, and TRUE/FALSE in winner if a winner
  536.  *        slot in scoreboard in i, and the tax bill in taxes.
  537.  *    Returns nothing of value
  538.  */
  539. new1sub(score, i, whoo, taxes)
  540. long    score, taxes;
  541. int    i;
  542. char    *whoo;
  543. {
  544.     struct wscofmt *p;
  545.  
  546.     p = &winr[i];
  547.     p->taxes += taxes;
  548.     if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) {
  549.         strcpy(p->who, whoo);          
  550.         strcpy(p->char_class, char_class);
  551.         p->score = score;
  552.         p->hardlev = c[HARDGAME];        
  553.         p->suid = userid;
  554.         p->timeused = gtime / 100;
  555.     }
  556. }
  557.  
  558.  
  559. /*
  560.  *    new2sub(score,i,whoo,whyded)           
  561.  *    int score,i,whyded,taxes;          
  562.  *    char *whoo;                       
  563.  *                Subroutine to put player into a 
  564.  *                non-winning scoreboard entry if his
  565.  *                score is high enough
  566.  *
  567.  *    Enter with the total score in gp in score,  players name in whoo,
  568.  *        died() reason # in whyded, and slot in scoreboard in i.
  569.  *    Returns nothing of value
  570.  */
  571. new2sub(score, i, whoo, whyded)
  572. long    score;
  573. int    i, whyded;
  574. char    *whoo;
  575. {
  576.     int    j;
  577.     struct scofmt *p;
  578.  
  579.     p = &sco[i];
  580.     if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) {
  581.         strcpy(p->who, whoo);  
  582.         strcpy(p->char_class, char_class);
  583.         p->score = score;
  584.         p->what = whyded;       
  585.         p->hardlev = c[HARDGAME];
  586.         p->suid = userid;          
  587.         p->level = level;
  588.         for (j = 0; j < 26; j++) { 
  589.             p->sciv[j][0] = iven[j]; 
  590.             p->sciv[j][1] = ivenarg[j]; 
  591.         }
  592.     }
  593. }
  594.  
  595.  
  596. /*
  597.  *        Subroutine to record who played larn, and what the score was
  598.  *    died(x)     
  599.  *    int x;
  600.  *
  601.  *    if x < 0 then don't show scores
  602.  *    died() never returns! (unless c[LIFEPROT] and a reincarnatable death!)
  603.  *
  604.  *        < 256    killed by the monster number
  605.  *        256        quit
  606.  *        257        suspended
  607.  *        258        self - annihilated
  608.  *        259        shot by an arrow
  609.  *        260        hit by a dart
  610.  *        261        fell into a pit
  611.  *        262        fell into a bottomless pit
  612.  *        263        a winner
  613.  *        264        trapped in solid rock
  614.  *        265        killed by a missing save file
  615.  *        266        killed by an old save file
  616.  *        267        caught by the greedy cheater checker trap
  617.  *        268        killed by a protected save file
  618.  *        269        killed his family and killed himself
  619.  *        270        erased by a wayward finger
  620.  *        271        fell through a bottomless trap door
  621.  *        272        fell through a trap door
  622.  *        273        drank some poisonous water
  623.  *        274        fried by an electric shock
  624.  *        275        slipped on a volcano shaft
  625.  *        276        killed by a stupid act of frustration
  626.  *        277        attacked by a revolting demon
  627.  *        278        hit by his own magic
  628.  *        279        demolished by an unseen attacker
  629.  *        280        fell into the dreadful sleep
  630.  *        281        killed by an exploding chest
  631.  *        282        killed by a missing maze data file
  632.  *        283        killed by a sphere of annihilation
  633.  *        284        died a post mortem death
  634.  *        285        malloc() failure
  635.  *        300        quick quit -- don't put on scoreboard
  636.  */
  637.  
  638. static int    scorerror;
  639.  
  640. died(x)
  641. int    x;
  642. {
  643.     int    f, win;
  644.  
  645.     if (c[LIFEPROT] > 0) /* if life protection */ {
  646.         switch ((x > 0) ? x : -x) {
  647.         case 256: 
  648.         case 257:
  649.         case 262: 
  650.         case 263:
  651.         case 265: 
  652.         case 266:
  653.         case 267: 
  654.         case 268:
  655.         case 269: 
  656.         case 271:
  657.         case 282: 
  658.         case 284:
  659.         case 285: 
  660.         case 300:  
  661.             goto invalid; /* can't be saved */
  662.         };
  663.         --c[LIFEPROT]; 
  664.         c[HP] = 1; 
  665.         --c[CONSTITUTION];
  666.         lprcat("\nYou feel wiiieeeeerrrrrd all over! ");
  667.         lflush();
  668.         beep();
  669.         sleep(4);
  670.         return; /* only case where died() returns */
  671.     }
  672. invalid:
  673.     sncbr();
  674.     f = 0;
  675.     if (ckpflag) 
  676.         unlink(ckpfile);    /* remove checkpoint file if used */
  677.  
  678.     if (x < 0) { 
  679.         f++; 
  680.         x = -x; 
  681.     }     /* if we are not to display the scores */
  682.  
  683.     if ((x == 300) || (x == 257))   {
  684.         clear();
  685.         lflush();
  686.         putchar('\n');
  687.         exit(0);/* for quick exit or saved game */
  688.     }
  689.  
  690.     if (x == 263)  
  691.         win = 1;  
  692.     else 
  693.         win = 0;
  694.  
  695.     c[GOLD] += c[BANKACCOUNT];   
  696.     c[BANKACCOUNT] = 0;
  697.  
  698.     /*    now enter the player at the end of the scoreboard */
  699.     newscore(c[GOLD], logname, x, win);
  700.  
  701.     clear();
  702.     lflush();
  703.     diedsub(x);    /* print out the score line */
  704.  
  705.     /*    wizards can't score*/
  706.     if ( !wizard ) {
  707.  
  708.     /*now for the scoreboard maintenance -- not for a suspended game*/
  709.         if (x != 257) {
  710.             if (sortboard())  
  711.                 scorerror = writeboard();
  712.         }
  713.     }
  714.     if ((x == 256) || (x == 257) || (f != 0))  {
  715.         exit(0);
  716.     }
  717.  
  718.     if (scorerror == 0) 
  719.         showscores();  /* if we updated the scoreboard*/
  720.  
  721.     if (x == 263) 
  722.         mailbill();
  723.  
  724.     putchar('\n');
  725.     exit(0);
  726. }
  727.  
  728.  
  729. /*
  730.  *    Subroutine to print out the line showing the player when he is killed
  731.  *    diedsub(x) 
  732.  *    int x;
  733.  */
  734. diedsub(x)
  735. int    x;
  736. {
  737.     char    ch, *mod, *cls;
  738.  
  739.     cls = class[c[LEVEL]-1];
  740.     puts("---------------------------------------------------------------");
  741.     puts("                 U L A R N    S C O R E S");
  742.     puts("---------------------------------------------------------------");
  743.     printf("Score: %ld  Diff: %d  ", c[GOLD], c[HARDGAME]);
  744.     printf("Level: %s  Char: %s\n", cls, char_class);
  745.     printf("\t%s", logname);
  746.     if (wizard) 
  747.         printf(" (wizard)");
  748.     if (x < 256) {
  749.         ch = *monster[x].name;
  750.         if(ch== 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
  751.             mod = "an";  
  752.         else 
  753.             mod = "a";
  754.         printf(" killed by %s %s", mod, monster[x].name);
  755.     } else {
  756.         int foo = x - 256;
  757.                if (!sex && (foo == 13 || foo == 22))
  758.             switch(foo) {
  759.             case 13 : 
  760.             printf(" killed her family and committed suicide");
  761.                 break;
  762.             case 22 :
  763.             printf(" hit by her own magic");
  764.                 break;
  765.             }
  766.         else
  767.             printf(" %s", whydead[foo]);
  768.        }
  769.  
  770.     if (x != 263)
  771.         printf(" on %s\n", levelname[level]);  
  772.     else 
  773.         putchar('\n');
  774.     puts("---------------------------------------------------------------");
  775.     fflush(stdout);
  776. }
  777.  
  778. showscore3(index)
  779. int    index;
  780. {
  781.     switch (iven[index]) {
  782.     case OPOTION:    
  783.         showscore1(index, potionname);  
  784.         break;
  785.     case OSCROLL:    
  786.         showscore1(index, scrollname);  
  787.         break;
  788.     case OLARNEYE:
  789.     case OBOOK:
  790.     case OSPIRITSCARAB:
  791.     case ODIAMOND:
  792.     case ORUBY:
  793.     case OCUBEofUNDEAD:
  794.     case OEMERALD:
  795.     case OCHEST:
  796.     case OCOOKIE:
  797.     case OSAPPHIRE:
  798.     case OORB:
  799.     case OHANDofFEAR:
  800.     case OBRASSLAMP:
  801.     case OURN:
  802.     case OWWAND:
  803.     case OSPHTALISMAN:
  804.     case ONOTHEFT:        
  805.         showscore1(index, (char **)0);  
  806.         break;
  807.     default:
  808.         printf("\n%c)   %s", index + 'a' , objectname[iven[index]]);
  809.         if (ivenarg[index] > 0)
  810.             printf(" + %d", (long)ivenarg[index]);
  811.         else if (ivenarg[index] < 0)
  812.             printf(" %d", (long)ivenarg[index]);
  813.         break;
  814.     }
  815.     if (c[WIELD] == index) 
  816.         puts(" (weapon in hand)");
  817.     if ((c[WEAR] == index) || (c[SHIELD] == index))  
  818.         puts(" (being worn)");
  819.     fflush(stdout);
  820. }
  821.  
  822. showscore1(idx, str2)
  823. int    idx;
  824. char    *str2[];
  825. {
  826.     if (str2 == 0)
  827.         printf("\n%c)   %s", idx + 'a' , objectname[iven[idx]]);
  828.     else if (*str2[ivenarg[idx]] == 0)
  829.         printf("\n%c)   %s", idx + 'a' , objectname[iven[idx]]);
  830.     else
  831.         printf("\n%c)   %s of%s", idx  + 'a' , 
  832.             objectname[iven[idx]], str2[ivenarg[idx]]);
  833. }
  834.